function CommonUtil() {

}

/**
 * 关闭窗口
 * 
 * @param {Object}
 *            model 模式
 */
CommonUtil.prototype.closeWindow = function(model) {
	if (model == 'ignore') {
		CommonUtil.prototype.closeWindows();
	} else {
		if (window.action == 'add' || window.action == 'edit') {
			mini.confirm("是否放弃本次修改", "提醒", function(action) {
				if (action == "ok") {
					CommonUtil.prototype.closeWindows();
				}
			});
		} else {
			CommonUtil.prototype.closeWindows();
		}
	}
}

/**
 * 关闭窗口
 */
CommonUtil.prototype.closeWindows = function() {
	if (window.CloseOwnerWindow) {
		window.CloseOwnerWindow();
	} else {
		window.close();
	}
}

/**
 * 重置表单
 * 
 * @param {String}
 *            formId 表单ID
 */
CommonUtil.prototype.reset = function(formId) {
	if (!formId) {
		formId = 'form';
	}
	var form = new mini.Form("#" + formId);
	form.clear();
}

/**
 * 获取选中的行
 * 
 * @param {String}
 *            gridId gridID
 * @return {Object} 行数据
 */
CommonUtil.prototype.getSelectRow = function(gridId) {
	if (!gridId) {
		gridId = 'datagrid';
	}
	var _grid = mini.get(gridId);
	var rows = _grid.getSelecteds();
	if (rows.length < 1 || rows.length > 1) {
		alert("请选中一条记录");
		return null;
	}
	return rows[0];
}

/**
 * 获取选中的行
 * 
 * @param {Object}
 *            gridId gridID
 * @return {Array} 多行数据
 */
CommonUtil.prototype.getSelectRows = function(gridId) {
	if (!gridId) {
		gridId = 'datagrid';
	}
	var _grid = mini.get(gridId);
	var rows = _grid.getSelecteds();
	if (rows.length < 1) {
		alert("请选中一条记录");
		return null;
	}
	return rows;
}

/**
 * 获取选中行的主键
 * 
 * @param {Object}
 *            gridId gridID
 * @param {String}
 *            field 主键key
 * @return {String} 主键字符串
 */
CommonUtil.prototype.getSelectKeys = function(gridId, field) {
	var rows = CommonUtil.prototype.getSelectRows(gridId);
	if (!rows) {
		return null;
	}
	var keys = [];
	$.each(rows, function(k, v) {
		keys.push(v[field]);
	});
	return keys.join(",");
}

/**
 * 遮罩
 * 
 * @param msg
 *            提示信息
 */
CommonUtil.prototype.mask = function(msg) {
	if (!msg) {
		msg = "处理中，请稍后";
	}
	mini.mask({
		cls : 'mini-mask-loading',
		html : msg + '...'
	});
}

/**
 * 取消遮罩
 */
CommonUtil.prototype.unmask = function() {
	mini.unmask();
}